﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace oms
{
    /// <summary>
    /// 管理器要继承的接口，后续可能有用。
    /// </summary>
    interface IManager
    {
    }

    /// <summary>
    /// 单例管理容器，不要定义太多单例了
    /// </summary>
    class ManagerContain
    {
        private Dictionary<Type, IManager> _managers = new Dictionary<Type, IManager>();
        /// <summary>
        /// 添加管理器
        /// </summary>
        public T AddManager<T>() where T :IManager
        {
            var type = typeof(T);
            if(_managers.ContainsKey(type))
            {
                throw new Exception(type.Name + " aready add!!");
            }

            IManager obj = Activator.CreateInstance<T>() as IManager;
            _managers.Add(type, obj);
            return (T)obj;
        }

        public T GetManager<T>() where T : IManager
        {
            var type = typeof(T);
            if (_managers.ContainsKey(type))
            {
                return (T)_managers[type];
            }
            throw new Exception(type.Name + " has not add to Facade");
        }
    }
}
